<?php
class RetrieveLog extends Model
{	
	
	public function getAgeInDays()
	{
		return Database::select_age_in_days($this->getTable(), $this->getId(), 'start_time');
	}
	
	/**
	 * @return string
	 */
	public function getDuration()
	{		
		$s = strtotime($this->finish_time) - strtotime($this->start_time);
		$m = floor($s / 60);
		$rs = $s%60;
		$h = floor($m / 60);
		$rm = $m%60;
		$d = floor($h/24);
		$rh = $h % 24;
		$w = floor($d/7);
		$rd = $d % 7;
		
		$duration = $rs .' seconde';
		if($rm)
		{
			$unit = 'minuten';
			if($w == 1)
			{
				$unit = 'minuut';
			}
			$duration = $rm.' '.$unit.', '.$duration;
		}
		
		if($h)
		{
			$duration = $rh.' uur, '.$duration;
		}
		
		if($d)
		{
			$unit = 'dagen';
			if($rd == 1)
			{
				$unit = 'dag';
			}
			$duration = $rd.' '.$unit.', '.$duration;
		}
		
		if($w)
		{
			$unit = 'weken';
			if($w == 1)
			{
				$unit = 'week';
			}
			$duration = $w.' '.$unit.', '.$duration;
		}
		return $duration; 		
	}
	
	/**
	 * @return RetrieveLog
	 */
	public static function getLast($where = array())
	{
		$aLogs = self::getAll($where = array(), 'id', 'desc', 1);
		return $aLogs[0];
	}
}